<?php
//provide datasource to connect to database
if (! function_exists ( "create_app_datasource" )) {
	function create_app_datasource($ds, $name) {
		global $cfg_opts;
		static $dm = null;
		if ($ds != null) {
			return $ds;
		}
		if ($dm == null) {
			$dm = new DataSourceManager ();
		}
		$name = empty ( $name ) ? 'default' : $name;
		if (! isset ( $cfg_opts ['ds'] [$name] )) {
			$cfg_opts ['ds'] [$name] = array ('driver' => defined ( "DS_DRIVER" ) ? DS_DRIVER : 'PdoMysql', 'encoding' => defined ( "DS_CHARSET" ) ? DS_CHARSET : 'UTF8', 'dbname' => defined ( 'DS_DATABASE' ) ? DS_DATABASE : 'test', 'prefix' => defined ( 'DS_TABLE_PREFIX' ) ? DS_TABLE_PREFIX : '', 'host' => defined ( 'DS_HOST' ) ? DS_HOST : 'localhost', 'user' => defined ( 'DS_USER' ) ? DS_USER : 'root', 'password' => defined ( 'DS_PASSWORD' ) ? DS_PASSWORD : '', 'pconnect' => defined ( 'DS_PCONNECT' ) ? DS_PCONNECT : false );
		}
		return $dm->getDataSource ( $name );
	}
}
bind ( 'get_app_datasource', 'create_app_datasource', 100, 2 );
?>